package footprint.kwlee.app.detail;

import java.util.List;

import footprint.kwlee.app.R;
import footprint.kwlee.app.db.*;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class DetailDialogAdapter extends BaseAdapter {
	private LayoutInflater inflater;
	private List<DetailItem> list;
	private Context context;
	
	public DetailDialogAdapter(Context context, List<DetailItem> list) {
		inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		this.list = list;
		this.context = context;
	}
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		int res = 0;
		if(convertView == null)
			convertView = inflater.inflate(R.layout.detail_item_layout, parent, false);
		
		DetailItem data = list.get(position);
			
		ImageView image = (ImageView) convertView.findViewById(R.id.DetailItemImage);
		TextView date = (TextView) convertView.findViewById(R.id.DetailDate);
		TextView content = (TextView) convertView.findViewById(R.id.DetailContent);
		TextView addr = (TextView) convertView.findViewById(R.id.DetailAddr);
		TextView time = (TextView) convertView.findViewById(R.id.Detailtime);
		
		date.setText(data.getDetail_date());
		content.setText(data.getDetail_memo());
		addr.setText(data.getDetail_addr());
		time.setText(data.getDetail_time());
		
		if(data.getPhoto1() != null)
			image.setImageDrawable(data.getPhoto1());
		else
			image.setImageResource(R.drawable.noimage); 
		
//		if(data.getPhoto2() != null)
//			image.setImageDrawable(data.getPhoto2());
//		else
//			image.setImageResource(R.drawable.noimage);
//		
//		if(data.getPhoto3() != null)
//			image.setImageDrawable(data.getPhoto3());
//		else
//			image.setImageResource(R.drawable.noimage);
		
		return convertView;
	}

}
